<?php
namespace app\serveraddress\logic;

use app\serveruser\logic\User;
use think\Db;
use \app\manage\logic\BaseLogic;
use \think\Loader;
/**
 * Created by PhpStorm.
 * User: 97606
 * Date: 2017/6/16
 * Time: 17:36
 */

class Address extends BaseLogic
{
    protected $name = 'address';
    protected $config = 'db_config_address';
    protected $classifyModel = 'app\serveraddress\model\Address';

    //添加新地区
    public function createAddress($data)
    {
        $rst = $this->db()->insert($data);

        if ($rst != 1) {
            return auto_failure (['status' => false],'添加新地区失败！');
        }
        return auto_return(['nums' => $rst],'添加新地区成功！');
    }

    // 编辑地区信息
    public function editAddress($data)
    {
        $rst = $this->model($this->classifyModel)
                    ->where('id',$data['id'])
                    ->update($data);
        if ($rst === false) {
            return auto_failure ($data,'地区信息更改失败！');
        } elseif ($rst === 0) {
            return auto_failure ($data,'地区信息未作改动！');
        }

        return auto_return(['number' => $rst],'地区信息更改成功！');
    }

    // 全部地区列表获取
    public function addressList()
    {
        $arr = $this->db()
                    ->select();
        $list = _make_tree($arr);
        return auto_return($list);
    }

    // 某一类地区列表获取
    public function someAddressList($data): array
    {
        $arr = $this->db()
                    ->where($data)
                    ->select();
        return auto_return($arr);
    }
}